package main
import(
	"fmt"
	"os"
	"bufio"
)
func main()  {
	filePath := "D:/test001.txt"
	file,err := os.OpenFile(filePath,os.O_RDWR|os.O_TRUNC,0644)
	if err != nil {
		fmt.Println("打开文件错误，错误信息：",err)
		return
	}
	defer file.Close()
	
	str := "你好\n"
	writer := bufio.NewWriter(file)
	for i := 0 ; i < 1 ; i++ {
	writer.WriteString(str)
	

	writer.Flush()
	content,err := os.ReadFile(filePath)
	if err != nil{
		fmt.Println("读取文件错误，错误信息：",err)
	}
	fmt.Println(string(content))
	fmt.Println("读取文件结束。。。")
}
}